package com.jd.oneday.month3;

import java.util.Scanner;

/**
 * 栈
 */
public class Day16_Test {
    public static void main(String[] args) {

        //创建一个栈
        Day16_Stack day16_stack = new Day16_Stack(4);
        //接受扫描器的值
        String key = "";
        //控制是否退出菜单
        boolean loop = true;
        //扫描器
        Scanner scanner = new Scanner(System.in);

        while (loop){
            System.out.println("show：表示显示栈");
            System.out.println("push：表示添加数据到栈（入栈）");
            System.out.println("pop：表示从栈取出数据（出栈）");
            System.out.println("exit：表示退出程序");
            System.out.println("请输入你的选择");
            key = scanner.next();
            switch (key){
                case "show":
                    day16_stack.list();
                    break;
                case "push":
                    System.out.println("请输入一个数");
                    int value = scanner.nextInt();
                    day16_stack.push(value);
                    break;
                case "pop":
                    try {
                        int res = day16_stack.pop();
                        System.out.println("出栈的数据是"+res);
                    }catch (Exception e){
                        System.out.println(e.getMessage());
                    }
                    break;
                case "exit":
                    scanner.close();
                    loop = false;
                    break;
                default:
                    break;
            }
        }
        System.out.println("程序退出");
    }
}
